import java.io.File;

public class FileDelete {
    public static void main(String[] args) {
        File file = new File("D:/a");
        deleteFile(file);
    }
    public static void deleteFile(File dir){
        if (dir == null || !dir.exists()){
            return;
        }

        if (dir.isFile()){
            dir.delete();
        }

        File[] files = dir.listFiles();

        if (files == null){
            return;
        }
        for (File fs : files) {
            if (fs.isFile()){
                fs.delete();
            }else {
                deleteFile(fs);
            }
        }
        System.out.println(dir.delete());
    }
}
